import requests

# 图片URL
image_url = "http://n.sinaimg.cn/news/crawl/117/w550h367/20220417/a3a9-08b2ca6dffe4210149dda424adf0734f.jpg"

# 桌面路径（假设您正在使用Windows系统）
desktop_path = "C:/Users/ASUS/Desktop/"

# 图片文件名（根据URL提取或自定义）
image_filename = "hello.jpg"

# 发起GET请求获取图片数据
response = requests.get(image_url, stream=True)

# 检查请求是否成功（HTTP状态码为200）
if response.status_code == 200:
    # 以二进制流方式打开本地文件用于写入
    with open(desktop_path + image_filename, "wb") as f:
        f.write(response.content)
    print(f"Image downloaded successfully and saved as {desktop_path + image_filename}")
else:
    print(f"Failed to download the image. HTTP status code: {response.status_code}")
